package Client;

import model.Student;

import java.util.ArrayList;
import java.util.Iterator;
import java.util.Scanner;

public class Function {
    ArrayList<Student> ls = new ArrayList<>();
    Scanner sc = new Scanner(System.in);
    // 增加
    public  Boolean add(){
        System.out.println("请输入你要添加的id");
        int id = sc.nextInt();
        System.out.println("请输入你要添加的姓名");
        String name = sc.next();
        System.out.println("请输入你要添加的年纪");
        int age = sc.nextInt();
        Student student = new Student(id,name,age);

        return ls.add(student);
    }
    // 删除
    public  void delete(int id){
        Iterator<Student> it = ls.iterator();
        System.out.println(ls.toString());
        while (it.hasNext()) {
            Student student = it.next();
            if (student.getId()==id) {
                it.remove();
                System.out.println("删除成功!");
            }
        }
    }
    // 修改
    public  void update(int id){

        //System.out.println("请输入你要修改的id");
        System.out.println("请输入你要修改的年纪");
        int age = sc.nextInt();
        System.out.println("请输入你要修改的姓名");
        String name = sc.next();
        for(Student student:ls){
            if (id==student.getId()){
                student.setAge(age);
                student.setName(name);
            }
        }
    }
    // 查询
    public  void query(int id){
        for (int i = 0; i <ls.size() ; i++) {
            if(id == ls.get(i).getId()){
                System.out.println(ls.get(i));
            }
        }
    }
}
